import hashlib
import struct
import zlib
import copy
import time

import sys
sys.path.append("./submitted_modules")
import submitter_names

LASTNAME = submitter_names.names[4]

# sha384 hash
def standard(data):
    star_list = data["stars"]
    hash_function = hashlib.sha384()
    star_data = ""
    for star in star_list:
        star_data+=struct.pack("fff", star["x"], star["y"], star["z"])
    hash_function.update(star_data)
    
    sha384 = str(int(hash_function.hexdigest(),16))
    return LASTNAME+"-SHA384-"+sha384[:7]

def cmp_function(test_f, data):
    data2 = copy.deepcopy(data)
    start = time.clock()
    name1 = test_f(data2)
    end = time.clock()
    dt1 = end-start

    start = time.clock()
    name2 = standard(data)
    end = time.clock()
    dt2 = end-start    
    
    if name1 != name2:
        raise Exception("Expected "+name2+", test_f returned "+name1)

    print "galaxy name:", name1

    print "submitted algorithm time:", dt1
    print "standard algorithm time:", dt2
    return True

def run_function(data):
    start = time.clock()
    name2 = standard(data)
    end = time.clock()
    dt2 = end-start    
    
    print "galaxy name:", name2

    print "standard algorithm time:", dt2
    return True
